<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>新闻公告</title>
	<link rel="stylesheet" href="../css/common2.css">

	<style>
		.one {
			width: 10%;
		}

		.two {
			width: 13%;
		}

		.three {
			width: 9%;
		}

		.photo {
			width: 50px;
			height: 50px;
		}

		td img {
			max-width: 50px;
			max-height: 50px;
		}
	</style>
</head>

<body>
	<div style="margin-top: 30px;"></div>
	<div v-if="able.add" id="vue-root">
		<div class="add"><a href="school_news_item.html" style="color: white">添加新闻</a></div>
		<div class="table">
			<table class="table_top">
				<thead>
					<tr>
						<th class="one">
							<input type="checkbox" class="check-box" v-model="all">序号
						</th>
						<th class="two">标题</th>
						<th class="two">时间</th>

						<th class="four">内容</th>
						<th class="three">编辑/删除</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(news,index) in list" :key="news.id">
						<td class="one">
							<input type="checkbox" class="check-box" v-model="news.checked">
							<span v-text="index+1"></span>
						</td>
						<td class="two" v-text="news.name"></td>
						<td class="two" v-text="news.time"></td>
						<td class="four" v-text="getText(news.intro)"></td>
						<td class="three">
							<div class="option">
								<div v-if="able.edit" class="edit-icon option-icon" @click="edit(news.id)"
									style="position: absolute; left: 20%; top: 30%;">
									<img class="img" src="../image/edit.png" height="20" width="20"
										onmouseover="this.src='../image/edit_light.png'"
										onmouseout="this.src='../image/edit.png'" />
								</div>
								<div v-if="able.del" class="delete-icon option-icon" @click="del([news.id])"
									style="right: 20%; top:30%;position: absolute;">
									<img class="img" src="../image/delete.png" height="20" width="20"
										onmouseover="this.src='../image/delete_light.png'"
										onmouseout="this.src='../image/delete.png'" />
								</div>
							</div>
						</td>
					</tr>

				</tbody>
			</table>
		</div>
		<br>
		<div class="delete" @click="batchDelete" v-if="able.del">批量删除</div>
		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
		</ul>
		<div v-if="bigimg">
			<div class="img_layer"></div>
			<img :src="bigimg?big_src:null" class="big_Img" @click="bigimg=false">
		</div>
	</div>
	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>

	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>
		var app = new Vue(merge({
			data: {
				bigimg: false,
				big_src: null,
				urls: {
					del: '/pc/news/del'
				}
			},
			created: function () {
				var schoolId = top_params().id;
				if (!schoolId) throw 'no school id';
				this.urls.list = '/pc/news/list/' + schoolId;
				this.getData();
				abled('news', this);
			},
			methods: {
				edit: function (id) {
					location.href = "school_news_item.html?id=" + id;
				},
				img: function (news) {
					if (!news.pic) return '../image/upload.svg';
					return '/static/' + news.schoolId + '/news/' + news.pic;
				},
				bigImg: function (news) {
					this.big_src = this.img(news);
					this.bigimg = true;
				},
				getText: function (html) {
					var b = document.createElement('div');
					b.innerHTML = html;
					var a = b.innerText;
					b.remove();
					if (a && a.length > 150)
						a = a.substr(0, 150) + '...';
					return a;
				},
			}
		}));
	</script>
</body>

</html>